<html>
<head>
	<title>Calculator</title>
</head>
<body>
<div id="help"></div>
<form action="calculator.php" method="get">
	<input type="text" name="expr" />
	<input type="submit" value="Submit" />
</form>
<?php
function check_exp($exp)
{
	return preg_match("/^\s*\-?[0-9]+(\.[0-9]*)?\s*((\+|\-|\*|\/)\s*\-?[0-9]+(\.[0-9]*)?\s*)*\s*$/", $exp);
}
$exp = $_GET['expr'];
if ($exp){
	if (check_exp($exp)){
		@eval('$result = (' . $exp . ');');
		echo "{$exp} = {$result}";
	} else {
		echo "Invalid input expression " . $exp;
	}
}
?>
</body>
</html>